from collections import OrderedDict

from rest_framework.pagination import PageNumberPagination

# 自定义分页类
from rest_framework.response import Response


class MyPageNumberPagination(PageNumberPagination):
    page_size = 1
    page_size_query_description = "pagesize"
    max_page_size = 99

    def get_paginated_response(self, data):
        res = {
            "data":{
                "houses": data,
                "total_page": self.page.paginator.num_pages
            },
            'errmsg': "请求成功",
            "errno": "0"
        }
        # return Response(OrderedDict([
        #     ('errmsg', "请求成功"),
        #     ('total_page', self.page.paginator.num_pages),
        #     ('houses', data),
        #     ("errno", "0")
        # ]))
        return Response(res)

